package com.starblink.product.detail.postrecommend

import android.app.Activity
import android.view.View
import com.starblink.android.basic.widget.dialog.BaseBottomSheetFragment
import com.starblink.android.common.view.expand.ExpandableTextView
import com.starblink.basic.autosize.utils.AutoSizeUtils
import com.starblink.basic.util.CommUtils
import com.starblink.basic.util.ScreenUtils
import com.starblink.product.databinding.DialogPostContentDetailBinding
import com.starblink.product.detail.postrecommend.data.PicPost
import com.starblink.rocketreserver.fragment.PostD

class PostContentDetailDialog(
    val activity: Activity,
    val post: PicPost,
) : BaseBottomSheetFragment() {
    lateinit var binding: DialogPostContentDetailBinding
    override fun getBindingRootView(): View {
        binding = DialogPostContentDetailBinding.inflate(layoutInflater)
        return binding.root
    }

    lateinit var data: MutableList<String>

    override fun initView() {

//        binding.tvName.text = "@ ${post.posterInfo.poster.username ?: ""}"
        if (post.content != null) {
            binding.tvTitle.visibility = View.VISIBLE
            val accountHashtagList: List<PostD.AccountHashtagList?> = post.accountHashtagList ?: listOf()

            val tvContent: ExpandableTextView = binding.tvTitle as ExpandableTextView
            val viewWidth: Int = ScreenUtils.getScreenWidth(activity) - AutoSizeUtils.dp2px(
                activity,
                48f
            )
            tvContent.initWidth(viewWidth)
            tvContent.maxLines = 500
            tvContent.setHasAnimation(true)
            tvContent.setCloseInNewLine(false)
            tvContent.setOpenSuffixColor(CommUtils.getColor(com.starblink.basic.style.R.color.sk_gray400))
            tvContent.setCloseSuffixColor(CommUtils.getColor(com.starblink.basic.style.R.color.sk_gray400))
            val topicChar =
                tvContent.replaceTopicSpan(
                    accountHashtagList,
                    post.content, com.starblink.basic.style.R.color.sk_gray500
                ) { ///跳转去hashtag详情
                        name, id ->
//                    activity.navigationTo(RoutePage.Post.PAGE_HASHTAG) {
//                        withString(RoutePage.Post.TOPIC_ID, id)
//                    }
                }
            tvContent.setOriginalText(
                topicChar
            )
        }

//        PostDetailHelp.showTopicView(activity, post.operatorHashtagList, binding.flTopic)

        binding.close.setOnClickListener {
            dismiss()
        }
    }

}